//
//  LDBaseTableViewController.swift
//  Weibo201655
//
//  Created by pro on 16/5/5.
//  Copyright © 2016年 LeeDan. All rights reserved.
//

import UIKit

class LDBaseTableViewController: UITableViewController {

    //判断用户是否已经登录过
    var userLogin: Bool = sharedUserAccount == nil
    
    override func loadView() {
        userLogin == false ? super.loadView() : setUpVistorView()
    }
    
    func setUpVistorView() {
        
        self.view = vistorView
        vistorView.vistorViewDelegate = self
  
        //设置vistorView信息
        if self is LDHomeTableViewController {
            vistorView.showVistorViewInfo(true, imageName: "visitordiscover_feed_image_smallicon", title: "关注一些人,看看有上面惊喜")
        } else if self is LDMessageTableViewController {
            vistorView.showVistorViewInfo(false, imageName: "visitordiscover_image_message", title: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        } else if self is LDDiscoverTableViewController {
            vistorView.showVistorViewInfo(false, imageName: "visitordiscover_image_message", title: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        } else if self is LDProfileTableViewController {
            vistorView.showVistorViewInfo(false, imageName: "visitordiscover_image_profile", title: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        //设置导航栏按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "vistorViewRegisterButtonClick")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "vistorViewLoginButtonClick")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    //MARK:lazy
    lazy var vistorView: LDVistorView = LDVistorView()

}

extension LDBaseTableViewController: LDVistorViewDelegate {
    //MARK: vistorView代理方法
    func vistorViewRegisterButtonClick() {
        print("vistorViewRegisterButtonClick")
    }
    
    func vistorViewLoginButtonClick() {
        // 跳转到授权控制器
        let oauthVC = LDOauthViewController()
        
        presentViewController(UINavigationController(rootViewController: oauthVC), animated: true, completion: nil)
    }
}
